package com.xiaochong.tir.manager.controller;

import com.github.pagehelper.PageInfo;
import com.xiaochong.tir.common.data.po.Summary;
import com.xiaochong.tir.manager.service.SummaryService;
import com.xiaochong.tir.manager.util.ManagerVersion;
import com.xiaochong.tir.manager.util.ReturnResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * @Author: WangXing
 * @Description:
 * @CreateDate: 2018/8/22 10:03
 */
@RestController
@RequestMapping(ManagerVersion.API_V1_PREFIX + "intro/")
@Api("简介管理")
public class SummaryController {

    @Autowired
    private SummaryService summaryService;

    /**
     * 简介管理页面
     * @return
     */
    @GetMapping("introList")
    public Object introPage(){
        return new ModelAndView("summary/introPage");
    }

    /**
     * 简介列表
     * @param summary
     * @return
     */
    @ApiOperation(value = "查询简介列表",notes = "查询简介列表")
    @PostMapping("selIntro")
    public Object selIntro(Summary summary){
        PageInfo<Summary> info = summaryService.selectByEntityLists(summary);
        return new ReturnResult<Summary>(0,"成功",info.getList(),info.getTotal());
    }

    /**
     * 简介编辑页面
     * @param id
     * @return
     */
    @GetMapping("editIntro/{id}")
    public Object editIntro(@PathVariable int id){
        Summary summary = summaryService.selectByPrimaryKey(id);
        ModelAndView mv = new ModelAndView("summary/editIntroPage");
        mv.addObject("summary",summary);
        return mv;
    }

    /**
     * 编辑方法
     * @param summary
     * @return
     */
    @ApiOperation(value = "编辑简介",notes = "编辑简介")
    @PostMapping("updateIntro")
    public Object updateIntro(Summary summary){
        summary.setUpdateTime(new Date());
        summaryService.updateByPrimaryKey(summary);
        return new ReturnResult<>(0,"成功",1,1);
    }

    /**
     * 新增页面
     * @return
     */
    @GetMapping("addIntro")
    public Object addIntro(){
        ModelAndView mv = new ModelAndView("summary/addIntroPage");
        return mv;
    }

    /**
     * 新增方法
     * @param summary
     * @return
     */
    @ApiOperation(value = "新增简介",notes = "新增简介")
    @PostMapping("insIntro")
    public Object insIntro(Summary summary){
        summary.setCreateTime(new Date());
        summary.setUpdateTime(new Date());
        summaryService.insertSelective(summary);
        return new ReturnResult<>(0,"成功",1,1);
    }

}
